#ifndef __MMFLAT_H
#define __MMFLAT_H
#include "stdtype.h"
#include "dlist.h"

/* the head type definition */
typedef struct
{
    mx_dlist_t list;        // element dlist, must be in first place
    mx_dlist_t flist;       // free dlist
    mx_uint8_t payload[];   // the start address of payload, this attribute does not take up structure space
} mx_mmflat_head_t, *mx_mmflat_head_pt;

/* the mmflat descriptor type definition */
typedef struct
{
    mx_void_pt start;       // start address of memory region
    mx_usize_t size;        // total size
    mx_usize_t fsize;       // free size
    mx_dlist_pt base;       // element chain base
    mx_dlist_pt fbase;      // free chain base
} mx_mmflat_t, *mx_mmflat_pt;

/* mmflat init */
void mx_mmflat_init (mx_mmflat_pt pmmflat, mx_void_pt start, mx_usize_t size);
/* allocate a memory space */
mx_void_pt mx_mmflat_alloc (mx_mmflat_pt pmmflat, mx_usize_t size);
/* free the specified memory space by address */
void mx_mmflat_free (mx_mmflat_pt pmmflat, mx_void_pt addr);
/* get the total memory of mmflat */
mx_usize_t mx_mmflat_total (mx_mmflat_pt pmmflat);
/* get the available memory of mmflat */
mx_usize_t mx_mmflat_available (mx_mmflat_pt pmmflat);
/* get the start address of memory */
mx_void_pt mx_mmflat_startaddr (mx_mmflat_pt pmmflat);

#endif
